<?php

namespace Beerus\Modules\Brand\Extensions\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

class BatchClaimWikiAudit extends BatchAction
{
    protected $action;

    public function __construct($action = 1)
    {
        $this->action = $action;
    }
    
    public function script()
    {
        return <<<EOT
            $('{$this->getElementClass()}').on('click', function() {
                           swal({
                                title: "确定批量通过已选择的数据吗？",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "确认",
                                showLoaderOnConfirm: true,
                                cancelButtonText: "取消",
                                preConfirm: function() {
                                //ajax
                                     $.ajax({
                                        method: 'post',
                                        url: '/admin/brand/wiki/audits',
                                        data: {
                                            _token:'{$this->getToken()}',
                                            ids: $.admin.grid.selected(),
                                            action: {$this->action}
                                        },
                                        success: function (e) {
                                            if (e.code == 1) {
                                            swal({
                                                title: e.title,
                                                type: "warning",
                                            });
                                                setTimeout(function () {
                                                    $.pjax.reload('#pjax-container');
                                                }, 1000);
                                            } else {
                                                toastr.error(e.title, null, {
                                                    timeOut : 3000
                                                }); 
                                            }
                                        }
                                    });
                              //ajax-end
                             }
            
                            });
                });
        EOT;
    }
}
